<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>注册页面表单校验</title>
		<script src="../global.js"></script>
		<style>
			* {
            margin: 0px;
            padding: 0px;
            box-sizing: border-box;
        }
            /*设置整体的尺寸、背景色、边距等*/
            width: 900px;
            height: 400px;
            border: 8px solid #eeeeee;
            background: #FAFAFA;
            margin: auto;
            margin-top: 20px;
        }

        .reg_left {
            /*设置左浮动和外边距*/
            float: left;
            margin: 10px;
        }

        .reg_left > p:first-child {
            /*设置段落（新用户注册）颜色和字体大小*/
            color: blueviolet;
            font-size: 20px;
        }

        .reg_left > p:last-child {
            /*设置段落（USER REGISTER）颜色和字体大小*/
            color: #A6A6A6;
            font-size: 20px;
        }

        .reg_center {
            /*设置中间的各种输入框等*/
            float: left;
            width: 500px;
        }

        .reg_right {
            /*设置右边段落浮动和外间距*/
            float: right;
            margin: 30px;
        }

        .reg_right > p:first-child {
            font-size: 15px;
        }

        .reg_right p a {
            /*设置超链接（立即登录）颜色*/
            color: crimson;
        }

        .td_left {
            /*设置表单中字体对齐方式和宽度、高度*/
            width: 100px;
            text-align: right;
            height: 40px;
        }

        .td_right {
            /*设置输入框内边距*/
            padding-left: 40px;
        }

        #username ,#password,#Email, #rename ,#Telphone,#Birthday,#checkcode{
            /*设置输入框大小和边框*/
            width: 220px;
            height: 30px;
            border: 1px solid #A4A4A4;
            /* 设置边框为圆角 */
            border-radius: 8px;
            padding-left: 10px;
        }
        #checkcode{
            /*验证码宽度*/
            width: 120px;
        }
        #img_check{
            /*验证码图片*/
            vertical-align: middle;
            height: 30px;
            width: 95px;
        }
        #btn_sub{
            /*注册按钮*/
            background: lime;
            width: 100px;
            height: 40px;
            border: 1px solid lime ;
        }
        .error{
            color:red;
            font-size:14px;
        }
        .success {
            color:yellowgreen;
            font-size:14px;
        }
        #td_sub{
            padding-left: 150px;
        }
    </style>

	</head>
	<body>

		<div class="reg_back">
			<div class="reg_left">
				<p>新用户注册</p>
				<p>USER REGISTER</p>
			</div>
			<div class="reg_center">
				<div class="reg_form">
					<form action="server.php" method="post" id="form">
						<table>
							<tr>
								<td class="td_left"><label for="username">用户名</label></td>
								<td class="td_right"><input type="text" name="username" placeholder="请输入用户名(英文字符或数字)" id="username">
									<span></span>
								</td>
							</tr>
							<tr>
								<td class="td_left"><label for="password">密码</label></td>
								<td class="td_right"><input type="password" name="password" placeholder="请输入密码（长度在6~12位之间）" id="password">
									<span></span>
								</td>
							</tr>
							<tr>
								<td class="td_left"><label for="Email">Email</label></td>
								<td class="td_right"><input type="email" name="email" placeholder="请输入Email" id="Email">
									<span></span>
								</td>
							</tr>
							<tr>
								<td class="td_left"><label for="rename">姓名</label></td>
								<td class="td_right"><input type="text" name="rename" placeholder="请输入真实姓名（中文姓名）" id="rename">
									<span></span>
								</td>
							</tr>
							<tr>
								<td class="td_left"><label for="Telphone">手机号</label></td>
								<td class="td_right"><input type="text" name="telphone" placeholder="请输入您的手机号" id="Telphone">
									<span></span>
								</td>
							</tr>
							<tr>
								<td class="td_left"><label>性别</label></td>
								<td class="td_right"><input type="radio" name="gender" value="male" checked> 男
									<input type="radio" name="gender" value="female"> 女
								</td>
							</tr>
							<tr>
								<td class="td_left"><label for="Birthday">出生日期</label></td>
								<td class="td_right"><input type="date" name="birthday" id="Birthday"></td>
							</tr>
							<tr>
								<td class="td_left"><label for="checkcode">验证码</label></td>
								<td class="td_right"><input type="text" name="checkcode" id="checkcode">
									<img src="img/code.png" id="img_check"></td>
								<!--10.png为验证码图片-->

							</tr>
							<tr>
								<td colspan="2" id="td_sub"><input type="submit" value="注册" id="btn_sub"></td>
							</tr>
						</table>
					</form>
				</div>
			</div>
			<div class="reg_right">
				<p>已有账号?<a href="#">立即登录</a></p>

			</div>
		</div>
		<script>
			/*
              var reg_password = /^\w{6,12}$/;
         */
			window.onload = function() {
				var username = document.getElementById("username");
				var password = document.getElementById("password");
				var email = document.getElementById("Email");
				var rename = document.getElementById("rename");
				var telphone = document.getElementById("Telphone");
				username.onblur = function() {
					var reg_username = /^([a-zA-Z0-9_-])/;
					// var flag=this.value.match(reg_username);
					var flag = reg_username.test(this.value);
					massage(username, flag, "用户名输入正确", "用户名格式有误");
					return flag;
				}
				password.onblur = function() {
					var reg_password = /^\w{6,12}$/;
					var flag = reg_password.test(this.value);
					massage(this, flag, "密码格式正确", "密码格式有误");
					return flag;
				}
				email.onblur = function() {
					var reg_email = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
					var flag = reg_email.test(this.value);
					massage(this, flag, "邮箱格式正确", "邮箱格式有误");
					return flag;
				}
				rename.onblur = function() {
					var reg_rename = /^[\u4e00-\u9fa5]{2,4}$/;
					var flag = reg_rename.test(this.value);
					massage(this, flag, "密码格式正确", "密码格式有误");
					return flag;
				}
				telphone.onblur = function() {
                var reg_telphone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
					var flag = reg_telphone.test(this.value);
					massage(this, flag, "电话格式正确", "电话格式有误");
					return flag;
				}
				document.getElementById("form").onsubmit=function(){
					return username.onblur()&&password.onblur()&&email.onblur()&&rename.onblur()&&telphone.onblur();
				}
				//提示信息
				function massage(obj, flag, successmsg, errormsg) {
					var messobj = cnext(obj);
					if (flag) {
						messobj.className = "success";
						messobj.innerHTML = successmsg;
					} else {
						messobj.className = "error";
						messobj.innerHTML = errormsg;
					}
				}
			}
		</script>
	</body>
</html>
